package com.vichat.user.util;

import com.vichat.common.constant.GlobalConstant;
import com.vichat.common.constant.I18nConstant;
import com.vichat.common.exception.ViChatException;
import com.vichat.common.util.I18NUtil;
import com.vichat.common.util.NumberUtils;
import com.vichat.user.service.IUserService;

import java.util.Locale;

public class CheckUtils {
    public static void checkEffetiveTerminalUserNumberMax(IUserService userService, long count) throws ViChatException {
        long countFDB = userService.countEffetiveTermianlUser();
        if (NumberUtils.isNotNullOrZero(countFDB) && (countFDB + count) > GlobalConstant.MAX_TERMINAL_AUTH_NUMBER) {
            String errorMsg = I18NUtil.getMessage("error_moreAuthNumber", null, Locale.getDefault());
            throw new ViChatException(I18nConstant.error_moreAuthNumber, errorMsg);
        }
    }
    public static void checkEffetiveDispatcherUserNumberMax(IUserService userService, long count) throws ViChatException {
        long countFDB = userService.countEffetiveDispatcherUser();
        if (NumberUtils.isNotNullOrZero(countFDB) && (countFDB + count) > GlobalConstant.MAX_DISPATCHER_AUTH_NUMBER) {
            String errorMsg = I18NUtil.getMessage("error_moreAuthNumber", null, Locale.getDefault());
            throw new ViChatException(I18nConstant.error_moreAuthNumber, errorMsg);
        }
    }
}
